package screen.component
{
	import com.greensock.TweenLite;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.utils.setInterval;
	import flash.utils.setTimeout;
	
	import helper.ValueObject;

	public class OtherAirplane extends Airplance
	{
		private const _DURATION:Number=10;
		private var _other_airplane1:MovieClip;
		private var _other_airplane2:MovieClip;
		private var _other_airplane3:MovieClip;
		public static var instance:OtherAirplane;
		public function OtherAirplane()
		{
			if(!instance){
				instance = this;
			}
			init();
		}
		public static function getInstance():OtherAirplane{
			if(!instance){
				instance = new OtherAirplane();
			}
			return instance;
		}
		private function init():void{
			_other_airplane1 =  ValueObject.C1_RESOURCE.getExportedAsset("otherAirPlane") as MovieClip;
			_other_airplane1.x = -100;
			addChild(_other_airplane1);
			
			_other_airplane2 =  ValueObject.C1_RESOURCE.getExportedAsset("otherAirPlane") as MovieClip;
			_other_airplane2.x = -100;
			addChild(_other_airplane2);
			
			_other_airplane3 =  ValueObject.C1_RESOURCE.getExportedAsset("otherAirPlane") as MovieClip;
			_other_airplane3.x = -100;
			addChild(_other_airplane3);
			tweenAirplane(_other_airplane3);
			setInterval(tweenAirplane,17000,_other_airplane1);
			setInterval(tweenAirplane,21000,_other_airplane2);
			setInterval(tweenAirplane,27000,_other_airplane3);
		}
		public function checkShoot(disp:DisplayObject):Boolean{
			if(_other_airplane1.hitTestObject(disp)){
				_other_airplane1.gotoAndPlay("fired");
				return true;
			}
			if(_other_airplane2.hitTestObject(disp)){
				_other_airplane2.gotoAndPlay("fired");
				return true;
			}
			if(_other_airplane3.hitTestObject(disp)){
				_other_airplane3.gotoAndPlay("fired");
				return true;
			}
			return false;
			//Tank.getInstance().shootCamiAirPlane(this);
		}
		private function airplaneClick(e:MouseEvent):void{
			//Tank.getInstance().shootOtherAirplane(this);
		}
		private function tweenAirplane(mc:MovieClip):void{
			mc.gotoAndPlay("normal");
			mc.y = 170+ 50*Math.random();
			mc.x = -150*Math.random();
			TweenLite.to(mc,_DURATION+5*Math.random(),{x:ValueObject.WIDTH + 50});
		}
	}
}